<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

	protected function _initSession(){
		Zend_Session::start();
	}
	
	protected function _initDb() {

		$dbOption = $this->getOption('resources');
		$dbOption = $dbOption['db'];

		// Setup database
		$db = Zend_Db::factory($dbOption['adapter'], $dbOption['params']);

		$db->setFetchMode(Zend_Db::FETCH_ASSOC);
		$db->query("SET NAMES 'utf8'");
		$db->query("SET CHARACTER SET 'utf8'");

		Zend_Registry::set('connectDB', $db);

		// Khi thiet lap che do nay model moi co the su dung duoc
		Zend_Db_Table::setDefaultAdapter($db);

		// Return it, so that it can be stored by the bootstrap
		return $db;
	}
	protected function _initLocale() {
		// define locale
		$locale = new Zend_Locale('vi');

		// register it so that it can be used all over the website
		Zend_Registry::set('Zend_Locale', $locale);
	}
	
	protected function _initMailConfig() {
		$resources = $this->getOption('resources');
		$mailOption = $resources['mail'];
		$transportOption = $mailOption['transport'];
		//init transport
		$settings = array('ssl' => $transportOption['ssl'],
                          'port' => $transportOption['port'],
                          'auth' => $transportOption['auth'],
                          'username' => $transportOption['username'],
                          'password' => $transportOption['password']);
		$transport = new Zend_Mail_Transport_Smtp($transportOption['host'], $settings);
		Zend_Registry::set('mailTransport', $transport);
		//init defaultFromEmail,defaultFromNmail
		$defaulFromOption = $mailOption['defaultFrom'];
		$defaultFrom = array('email' => $defaulFromOption['email'],
							 'name' => $defaulFromOption['name']);
		Zend_Registry::set('defaultFrom', $defaultFrom);
		//init defaultReplyToEmail,defaultReplyToName
		$defaultReplyToOption = $mailOption['defaultReplyTo'];
		$defaultReplyTo = array('email' => $defaultReplyToOption['email'],
							 	'name' => $defaultReplyToOption['name']);
		Zend_Registry::set('defaultReplyTo', $defaultReplyTo);
		return $transport;
	}
}